package main

import (
	"fmt"
	"io/ioutil"
)

func main() {
	path:="D:\\ibay图片\\ibay图\\独立站白底图"
	dir, err := ListDir(path)
	if err != nil {
		return
	}

	path2:="D:\\ibay图片\\ibay图\\独立站白底图2"
	dir2, err := ListDir(path2)
	if err != nil {
		return
	}
	//fmt.Println(dir)
	fmt.Println("文件1有：",len(dir))
	//fmt.Println(dir2)
	fmt.Println("文件2有：",len(dir2))
	tempArr:= append(dir, dir2...)
	res:=RemoveRepByMap(tempArr)
	fmt.Println("总共有：",len(res))
	fmt.Println("重复的有：",len(dir)+ len(dir2)- len(res))
}


func ListDir(dirPth string) (files []string, err error) {
	files = make([]string, 0, 0)
	dir, err := ioutil.ReadDir(dirPth)
	if err != nil {
		return nil, err
	}
	for _, fi := range dir {
		if !fi.IsDir() { // 忽略目录
			continue
		}
		files = append(files, fi.Name())
	}

	all := make([]string, 0, 0)
	for _, file := range files {
		filee, _ := ioutil.ReadDir(dirPth+"\\"+file)
		for _, fi := range filee {

			if !fi.IsDir() { // 忽略目录
				continue
			}
			all=append(all, fi.Name())
		}
	}

	return all, nil
}

func RemoveRepByMap(slc []string) []string {
	result := []string{}
	tempMap := map[string]byte{} // 存放不重复主键
	for _, e := range slc {
		if e == "0" {
			continue
		}
		l := len(tempMap)
		tempMap[e] = 0
		if len(tempMap) != l { // 加入map后，map长度变化，则元素不重复
			result = append(result, e)
		}
	}
	return result
}